// fluro路由的配置 (处理页面的跳转)
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:hkzf_flutter/pages/community_picker.dart';
import 'package:hkzf_flutter/pages/layout/index.dart';
import 'package:hkzf_flutter/pages/loading.dart';
import 'package:hkzf_flutter/pages/login.dart';
import 'package:hkzf_flutter/pages/not_found.dart';
import 'package:hkzf_flutter/pages/register.dart';
import 'package:hkzf_flutter/pages/roomAdd/index.dart';
import 'package:hkzf_flutter/pages/room_detail/index.dart';
import 'package:hkzf_flutter/pages/room_manage/index.dart';
import 'package:hkzf_flutter/pages/search/index.dart';
import 'package:hkzf_flutter/pages/setting.dart';

class Routes {
   // 定义路由名称
   // 主页面路径(为/时为根路径首页的路径)
   static String layout = '/';
   // 登录页面路径
   static String login = '/login';
   // 注册页面路径
   static String register = '/register';
   // 搜索页面路径
   static String search = '/search';
   // 设置页面路径
   static String setting = '/setting';
   // 小区选择页面路径
   static String communityPicker = '/communityPicker';

   // 房屋管理页面路径
   static String roomManage = '/roomManage';
   // 房屋详情页面路径
   static String roomDetail = '/roomDetail/:roomId';
   // 房源发布页面路径
   static String roomAdd = '/roomAdd';
   
   // 加载页面路径
   static String loading = '/loading';



   // 定义路由处理函数
   static Handler layoutHandler = Handler(// 主页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const Layout();
     }
   );
   static Handler loginHandler = Handler(// 登录页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const LoginPage();
     }
   );
   static Handler registerHandler = Handler(// 注册页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const RegisterPage();
     }
   );
   static Handler searchHandler = Handler(// 搜索页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const SearchPage();
     }
   );
   static Handler settingHandler = Handler(// 设置页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const SettingPage();
     }
   );
    static Handler roomManageHandler = Handler(// 房屋管理页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const RoomManagePage();
     }
   );
   static Handler communityPickerHandler = Handler(// 小区选择路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const CommunityPicker();
     }
   );
   static Handler roomDetailHandler = Handler(// 房屋详情页面路径
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       //通过params获取路由参数 (假如！空安全检查)
       return RoomDetailPage(roomId: params['roomId']![0]);
     }
   );
    static Handler roomAddHandler = Handler(// 房源发布页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const RoomAddPage();
     }
   );
   static Handler loadingHandler = Handler(// 加载页面路径处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const LoadingPage();
     }
   );



   static Handler notFoundHandler = Handler(// 404页面路径(未匹配到路径)处理
     handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       return const NotFoundPage();
     }
   );
  
   // 编写configureRoutes 关联路由名称和处理函数
   static void configureRoutes(FluroRouter router) {
    // TransitionType.native	使用平台默认动画（Android 左右滑动 / iOS 从下往上）
    // TransitionType.material	Material Design 动画（Android 风格）
    // TransitionType.cupertino	iOS 风格动画
    // TransitionType.fadeIn	淡入动画
    // TransitionType.inFromLeft	从左侧进入
    // TransitionType.inFromRight	从右侧进入
    // TransitionType.inFromTop	从上方进入
    // TransitionType.inFromBottom	从下方进入
    // TransitionType.noTransition	无动画
     // transitionType:设置页面切换动画形式
     router.define(layout, handler: layoutHandler);
     router.define(login, handler: loginHandler,transitionType: TransitionType.material);
     router.define(register, handler: registerHandler,transitionType: TransitionType.fadeIn);
     router.define(search, handler: searchHandler);
     router.define(setting, handler: settingHandler);
     router.define(communityPicker, handler: communityPickerHandler,transitionType: TransitionType.fadeIn);

     router.define(roomManage, handler: roomManageHandler,transitionType: TransitionType.fadeIn);
     router.define(roomDetail, handler: roomDetailHandler,transitionType: TransitionType.cupertino);
     router.define(roomAdd, handler: roomAddHandler,transitionType: TransitionType.fadeIn);

     router.define(loading, handler: loadingHandler,transitionType: TransitionType.fadeIn);
     router.notFoundHandler = notFoundHandler;

   }

}